package com.ywl.exercise.service.impl;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Propagation;

import com.ywl.exercise.dao.GameDao;
import com.ywl.exercise.dao.ImageDao;
import com.ywl.exercise.entity.GameEntity;
import com.ywl.exercise.entity.vo.ImageVoEntity;
import com.ywl.exercise.service.GameService;


@Service
@Transactional(propagation = Propagation.REQUIRED)
@TransactionConfiguration(transactionManager = "txManager", defaultRollback = true)
public class GameServiceImpl implements GameService {
	@Resource
	private GameDao gameDaoImpl; 
	@Resource
	private ImageDao imageDaoImpl; 

	@Override
	public int saveGame(GameEntity entity) {
		return gameDaoImpl.saveGame(entity);
	}
	
	@Override
	public void updateGame(GameEntity entity) {
		gameDaoImpl.updateGame(entity);
	}

	@Override
	public GameEntity findById(Integer gameid) {
		return gameDaoImpl.findById(gameid);
	}

	@Override
	public Map<Integer, List<ImageVoEntity>> startGame(GameEntity entity) {
		//创建一个小游戏
		int gameid = gameDaoImpl.saveGame(entity);
		
		//创建一个map对象
		Map<Integer, List<ImageVoEntity>> map = new HashMap<Integer, List<ImageVoEntity>>();
		
		map.put(gameid, imageDaoImpl.findImageVo());
		return map;
	}
}
